package com.github.springcloud.good.service;

import com.github.springcloud.good.api.GoodService;
import com.github.springcloud.good.dto.CreateGoodDto;
import com.github.springcloud.good.po.Good;
import com.github.springcloud.good.vo.GoodVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by zhaozuowen on 2018/7/12.
 */
@Service
public class GoodServieImpl implements GoodService {


    public static final ConcurrentHashMap<String,Good> goodStorage=new ConcurrentHashMap<>();
    @Override
    public GoodVo getByGoodNo(String goodNo) {

        GoodVo goodVo=null;

        Good good=goodStorage.get(goodNo);

        if(null!=good){
            goodVo=new GoodVo();
            BeanUtils.copyProperties(good,goodVo);
        }
        return goodVo;
    }

    @Override
    public void createGood(CreateGoodDto createGoodDto) {

        Good good=new Good();
        BeanUtils.copyProperties(createGoodDto,good);

        good.setId(UUID.randomUUID().toString());
        good.setGoodNo(UUID.randomUUID().toString());
        goodStorage.put(good.getGoodNo(),good);


    }
}
